package main

import (
	"fmt"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

type Snowball struct {
	Id   int
	Code string
}

type StockDay struct {
	Id              int64
	SnowballId      int
	DayQuantity     int
	DayOpeningPrice float64
	DayMaxPrice     float64
	DayMinPrice     float64
	DayClosePrice   float64
	DayMaxMinPrice  float64
	DayMaxMinRange  float64
	DayTurnoverRate float64
	DayTotalPrice   float64
	DayDate         string
}

func main() {
	dsn := "root:password@tcp(xx.xx.xx.xx:xx)/db_name?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		fmt.Println("数据库连接失败!")
	}

	sb := Snowball{}
	db.Table("snowball").Where("code = ?", "SZ301018").Find(&sb)

	sd := StockDay{}
	sd.SnowballId = sb.Id
	sd.DayQuantity = 1
	sd.DayOpeningPrice = 2.1
	sd.DayMaxPrice = 3.1
	sd.DayMinPrice = 4.1
	sd.DayClosePrice = 5.1
	sd.DayMaxMinPrice = 6.1
	sd.DayMaxMinRange = 7.1
	sd.DayTurnoverRate = 8.1
	sd.DayTotalPrice = 9.1
	sd.DayDate = "2021-07-20"
	db.Table("stock_day").Create(&sd)
}
